<template>
	<view class="job-box">
		<view class="hd fboxRow Ycenter " @click="goPage">
			<view class="title font32 flex1 font-ell1 fwb">{{ innerData.jobName }}</view>
			<view class="fboxCol Yend font28 salary color-E8CDA7">
				<text v-if="innerData.jobStatus == 2">停止招聘</text>
				<template v-else>
					<text v-if="innerData.salaryMin == 0">面议</text>
					<text v-else>{{ unitNum(innerData.salaryMin) }}-{{ unitNum(innerData.salaryMax) }}</text>
					<view class="fboxRow Ycenter mt10" v-if="type != 'detailCollection'">
						<!-- <RateItem :num="innerData.matchRate" size="font20" /> -->
						<view class="rate-item fboxRow Ycenter">
							<text v-for="(item, index) in 5" :key="index" class="bwfont font20"
							:class="[item <= innerData.matchRate ? 'bw-a-ziyuan1' : 'bw-a-ziyuan11']"
							style="color:'#CC9870';margin-left: 6rpx;"
							></text>
						</view>
					</view>
				</template>
			</view>
		</view>
		<view class="bd" @click="goPage">
			<template v-if="type == 'concise'">
				<view class="intr fboxRow Ycenter color-ACB4C7 mt24 font30">
					<text class="font-ell2 lh40">
						工作介绍，接口还为对接，两行
					</text>
				</view>
			</template>
			<template v-else>
				<view class="company fboxRow Ycenter color-ACB4C7 mt24 font30">
					<text class="font-ell1 lh40 mr24">{{ innerData.companyName }}</text>
				</view>
				<view class="company fboxRow Ycenter color-ACB4C7 mt24 font30">
					<text class="text-nowrap mr24">{{ innerData.staffSize }}</text>
					<text class="text-nowrap flex1 fboxRow Xend">{{innerData.industryName}}</text>
				</view>
			</template>
			<view class="tags fboxWrap mt30" v-if="innerData.jobKeywordList && innerData.jobKeywordList.length">
				<view class="tag font-ell1 fboxRow Ycenter Xcenter font22"
					v-for="(item, index) in innerData.jobKeywordList" :key="index">{{ item }}</view>
			</view>
			<view class="fboxRow Ycenter mt26">
				<image class="avatar" :src="innerData.creatorAvatar || innerData.creatorMemberAvatar" mode="aspectFill">
				</image>
				<view class="flex1 fboxRow Ycenter">
					<view class="name font-ell1 font28">{{ innerData.creatorName || innerData.creatorMemberName }}
					</view>
					<view class="info fboxRow Ycenter font28">
						<text class="font-ell1">{{ innerData.positionName }}</text>
					</view>
				</view>
				<view class="address font28 font-ell1">{{ innerData.workArea || '' }}</view>
			</view>
		</view>
		<template v-if="type != 'enterpriseDetail' && type != 'detailCollection' && type!= 'recruitmentIndex' && type!= 'concise'">
		<view class="ft mt40 fboxRow Ycenter Xend">
			<view class="flex1">
				<text class="font26 lh38 color-6B707C" v-if="type == 'deliverPage'">投递时间：{{ innerData.gmtSend }}</text>
				<text class="font26 lh38 color-ACB4C7"
					v-if="type == 'myInterview'">面试时间：{{ getNowDate(innerData.gmtInterview) }}</text>
				<text class="font26 lh38 color-6B707C" v-if="type == 'collectPage'">{{ innerData.gmtCollect }}</text>
			</view>
			<view class="btn-group fboxRow" v-if="innerData.jobStatus == 1 || type == 'recruitmentList'">
				<view class="btn fboxRow Ycenter Xcenter font26"
					v-if="type == 'recruitmentList'" :class="[_innerData.isSend ? 'btn-bg' : 'btn-border']"
					@click="deliverTap(_innerData)">
					{{ _innerData.isSend ? '已投递' : '投简历' }}
				</view>
				<template v-if="type == 'collectPage'">
					<view class="btn fboxRow Ycenter Xcenter btn-bg font26" v-if="_innerData.sendFlag">
						已投递</view>
					<view class="btn fboxRow Ycenter Xcenter btn-border font26" v-else
						@click="deliverTap(_innerData)">投简历</view>
				</template>
				<view class="btn fboxRow Ycenter Xcenter bg-linear color-141720 font26" @click="goApp('contact')">沟通一下
				</view>
			</view>
		</view>
		</template>
		<ModelPublic ref="modelRef" content="确定是否投送简历？" @confirm="inviteTap" />
	</view>
</template>

<script>
	import {
		unitNum
	} from '@/static/js/common.js';
	import ModelPublic from '@/components/model-public/index.vue'
	// import RateItem from '../components/rate-item.vue';
	import {
		deliverJob,
		jobCommunicate
	} from '@/api/recruit.js';
	export default {
		props: {
			type: {
				type: String,
				default: '' // deliverPage 投过的职位 | myInterview我的面试 | collectPage职位收藏 | recruitmentList 数字招聘列表 | recruitmentIndex 招聘首页 | concise 扫码访问企业招聘首页 | detailCollection 商务名片招聘
			},
			innerData: {
				type: Object,
				default: () => {
					return {};
				}
			}
		},
		components: {
			ModelPublic
		},
		data() {
			return {
				unitNum,
				isDeliver: false,
				isVitaModal: false
			};
		},
		computed: {
			_innerData: {
				get() {
					return this.innerData;
				},
				set(val) {
					this.$emit('update:innerData', val);
				}
			}
		},
		methods: {
			goPage() {
				const id = this.innerData.id;
				this.$pageTo('/recruit/enterprise/enterpriseDetail?id=' + id + '&companyId=' + this.innerData
					.companyId);
			},
			deliverTap() {
				if (this.type == 'recruitmentList') {
					this.$emit('deliver', this._innerData)
				} else {
					if (!this._innerData.isSend) {
						const vitaTemp = getApp().globalData.vitaTemp;
						if(vitaTemp.resumeOpen){
							this.$refs.modelRef.show = true
						}else{
							this.$emit('perfect')
						}
					}
				}
			},
			inviteTap() {
				deliverJob({
					jobId: this.innerData.id
				}).then(res => {
					if (res.data) {
						this.$refs.modelRef.show = false
						this._innerData.isSend = true;
						this._innerData.sendFlag = true;
						uni.showToast({
							icon: 'none',
							title: '简历投递成功'
						});
					}
				});
			},
			getNowDate(d) {
				let date = new Date(d);
				let sign2 = ':';
				let year = date.getFullYear(); // 年
				let month = date.getMonth() + 1; // 月
				let day = date.getDate(); // 日
				let hour = date.getHours(); // 时
				let minutes = date.getMinutes(); // 分
				let seconds = date.getSeconds(); //秒
				let weekArr = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
				let week = weekArr[date.getDay()]; //getDay() 从 Date 对象返回一周中的某一天 (0 ~ 6)
				let noon = '上午';
				// 给一位数的数据前面加 “0”
				// if (month >= 1 && month <= 9) {
				//     month = "0" + month;
				// }
				// if (day >= 0 && day <= 9) {
				//     day = "0" + day;
				// }
				if (hour >= 0 && hour <= 9) {
					hour = '0' + hour;
				}
				if (minutes >= 0 && minutes <= 9) {
					minutes = '0' + minutes;
				}
				if (seconds >= 0 && seconds <= 9) {
					seconds = '0' + seconds;
				}
				if (hour > 12) {
					noon = '下午';
				}
				const edate = month + '月' + day + '日（' + week + '）' + noon + ' ' + hour + sign2 + minutes;
				return edate;
			},
			goApp(type) {
				if (type == 'contact') {
					const memberId = this._innerData.creatorMemberId || this._innerData.creatorId;
					const data = {
						type: 'contact',
						memberId: memberId,
						userName: this._innerData.creatorName
					};
					jobCommunicate({
						id: this._innerData.id
					}).then(res => {});
					this.$bridge.callHandler('recruitHandler', data, () => {
						console.log('recruitHandler', '返回');
					});
				}
			}
		}
	};
</script>

<style lang="scss" scoped>
	.max-w70 {
		max-width: 70%
	}

	.text-nowrap {
		white-space: nowrap;
	}

	.job-box {
		margin-bottom: 24rpx;
		padding: 24rpx;
		border-radius: 12rpx;
		background-color: var(--viewBgColor);
	}

	.job-box .salary{color: #FE6850}
	.job-box .salary .bwfont{margin-left: 4rpx;color: var(--buttonOutlineOneColor)}

	.job-box .title {
		line-height: 50rpx;
	}

	.job-box .tags {
		height: 48rpx;
		overflow: hidden;
	}

	.job-box .tags .tag {
		padding: 0 12rpx;
		// width: 104rpx;
		max-width: 200rpx;
		height: 40rpx;
		line-height: 40rpx;
		border-radius: 20rpx;
		text-align: center;
		background: #F4F8FB;
		color:var(--contentFontFourColor);
		
	}

	.job-box .tags .tag+.tag {
		margin-left: 16rpx;
	}

	.job-box .name {
		margin-right: 30rpx;
		max-width: 150rpx;
		height: 38rpx;
		line-height: 38rpx;
	}

	.job-box .info {
		line-height: 38rpx;
		max-width: 200rpx;
	}

	.job-box .avatar {
		margin-right: 12rpx;
		width: 32rpx;
		height: 32rpx;
		border-radius: 50%;
		overflow: hidden;
	}

	.job-box .address {
		line-height: 38rpx;
		max-width: 160rpx;
		color: var(--contentFontFourColor)
	}

	.job-box .btn-group {}

	.job-box .btn-group .btn {
		width: 136rpx;
		height: 56rpx;
		border-radius: 12rpx;
	}

	.job-box .btn-group .btn+.btn {
		margin-left: 18rpx;
	}
	.job-box .btn-group .btn-bg{background-color: var(--backgroundDivisionColor);color:var(--contentFontFourColor)}
	.job-box .btn-group .btn-border{border:1rpx solid var(--buttonOutlineOneColor);color:var(--buttonOutlineOneColor)}
	.name, .info{color: var(--contentFontFourColor)}
</style>